﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using OGS.Contracts;
namespace OGS.DataAccess
{

    /// <summary>
    /// Class for roles
    /// </summary>
    public class DARoles
    {
        private static readonly DARoles instance;
        /// <summary>
        /// Initializes a static instance of the DARoles class with no arguments.
        /// </summary>
        static DARoles()
        {
            instance = new DARoles();
        }
        /// <summary>
        /// Initializes a new instance of the DARoles class with no arguments.
        /// </summary>
        private DARoles() { }
        /// <summary>
        /// The Instance of DARoles class
        /// </summary>
        public static DARoles Instance
        {
            get
            {
                return instance;
            }
        }
        public List<Role> GetAllActiveRoles()
        {
            DataTable dt = new DataTable();
            List<Role> lstRole = new List<Role>();
            using (DBManager dbm = new DBManager("Stp_Get_Roles"))
            {
                dbm.ExecuteNonQuery();
                dt = dbm.GetDataTable();
            }
            foreach (DataRow dr in dt.Rows)
            {
                Role objRoles = PopulateRoles(dr);
                lstRole.Add(objRoles);
            }
            return lstRole;
        }
        /// <summary>
        /// Populating roles
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        public Role PopulateRoles(DataRow dr)
        {
            Role oRole = new Role();
            oRole.RoleID = Convert.ToInt32(dr["PK_RoleID"]);
            oRole.Name = Convert.ToString(dr["Name"]);
            oRole.IsActive = Convert.ToBoolean(dr["IsActive"]);
            return oRole;
        }
    }
}
